// pages/aduting/resversion/reversion_detail.js
var util = require('../../../utils/util.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: '',
    images: ['/images/off.png', '/images/ON.png'],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    wx.getStorage({
      key: 'userInfo',
      success: function (res) {
        that.setData({
          userInfo: res.data,
          id: options.id,
        })

        util.getReq("/app/my/tenantDetail", {
          source: res.data.source,
          uid: res.data.uid,
          'checkIn.checkIn_id': that.data.id

        }, function (datas) {
          if (datas.code == 0) {
            console.log(datas.data.ds);
            that.setData({
              resversionDetail: datas.data,
              checkIn_date: util.format(datas.data.checkIn_date, 'yyyy-MM-dd'),
              retreat_room_time: util.format(datas.data.retreat_room_time,'yyyy-MM-dd'),
              isLock: datas.data.ds
            })

          } else {
            wx.showToast({
              title: datas.desc,
            })
          }

        })
      }, fail: function () {
        wx.redirectTo({
          url: '/pages/index/index',
        })
      }
    });
  },
  bindOpenSe:function(e){
    var that=this;
    var ds = e.currentTarget.dataset.islock==0?1:0;
    util.getReq("/app/my/updateLockPower", {
      source: that.data.userInfo.source,
      uid: that.data.userInfo.uid,
      'checkIn.checkIn_id': that.data.id,
      'checkIn.ds': ds,
      'user.user_id': that.data.userInfo.uid
    }, function (datas) {
      if (datas.code == 0) {
        wx.showToast({
          title: '开锁权限改成功',
          
        })
        var sta=e.currentTarget.dataset.islock==1?0:1;
        that.setData({
          isLock: sta
        })

      } else {
        wx.showToast({
          title: datas.desc,
        })
      }

    })
  }
    
  
})